package com.tiyende.credit.loop.ui.adapter

import android.graphics.Color
import androidx.recyclerview.widget.RecyclerView
import com.lib.common.adapter.CommonRecyclerViewAdapter
import com.lib.common.adapter.CommonViewHolderHelper
import com.lib.common.shapeview.layout.ShapeLinearLayout
import com.tiyende.credit.loop.R
import org.json.JSONObject

/**
 * TiyendeCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/19 10:43
 * @Annotation：校验手机号类型适配器
 */
class TiyendeCheckMobileTypeAdapter(recyclerView: RecyclerView?) : CommonRecyclerViewAdapter<JSONObject>(recyclerView,R.layout.tiyende_activity_check_mobile_type_item) {

    override fun setItemChildListener(helper: CommonViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.checkTypeLayout)
    }

    override fun fillData(helper: CommonViewHolderHelper, position: Int, model: JSONObject) {
        val imageCheckTypeIcon = helper.getImageView(R.id.imageCheckTypeIcon)
        imageCheckTypeIcon.setImageResource(model.optInt("checkTypeIcon"))
        helper.setText(R.id.textCheckType,model.optString("checkTypeTitle"))

        val checkTypeLayout = helper.getView<ShapeLinearLayout>(R.id.checkTypeLayout)
        val imageCheckTypeSelect = helper.getImageView(R.id.imageCheckTypeSelect)
        when(model.optBoolean("isSelected",false)){
            true -> {
                checkTypeLayout.shapeDrawableBuilder
                    .setSolidColor(Color.parseColor("#000000"))
                    .setStrokeColor(Color.parseColor("#FF3ED9AB"))
                    .intoBackground()
                imageCheckTypeSelect.setImageResource(R.mipmap.tiyende_login_check_selected)
            }
            else -> {
                checkTypeLayout.shapeDrawableBuilder
                    .setSolidColor(Color.parseColor("#000000"))
                    .setStrokeColor(Color.parseColor("#000000"))
                    .intoBackground()
                imageCheckTypeSelect.setImageResource(R.mipmap.tiyende_login_check_normal)
            }
        }
    }
}